package main

import (
	"time"
	"fmt"
)

//select的特点是只要其中一个case已经完成，程序就会继续往下执行，
//而不会考虑其他case的情况。

/*func server1(ch chan string) {
	time.Sleep(6 * time.Second)
	ch <- "from server1"
}

func server2(ch chan string) {
	time.Sleep(3 * time.Second)
	ch <- "from server2"
}*/

func server3(ch chan string) {
	ch <- "from server3"
}

func server4(ch chan string) {
	ch <- "from server4"
}

func main() {
	/*output1 := make(chan string)
	output2 := make(chan string)
	go server1(output1)
	go server2(output2)
	select {
	case s1 := <-output1:
		fmt.Println(s1)
	case s2 := <-output2:
		fmt.Println(s2)
	}*/

	output3 := make(chan string)
	output4 := make(chan string)
	go server3(output3)
	go server4(output4)
	time.Sleep(1 * time.Second)
	select {
	case s3 := <-output3:
		fmt.Println(s3)
	case s4 := <-output4:
		fmt.Println(s4)
	}
}
